#include "tickcountrunnableunix.hpp"


void TickCountRunnableUnix::run()
{
    setIsRunning(true);

    /* TODO: Implement Processor Affinity under UNIX */
    /* BUG: These functions cannot be compiled under Windows */
    // Set the current Threads processor affinity
    //int affinity = property("id").toInt() % QThread::idealThreadCount();
    //cpu_set_t mask;
    //CPU_ZERO(&mask);
    //CPU_SET((affinity - 1), &mask);
    //pthread_setaffinity_np (pthread_self(), sizeof(cpu_set_t), &mask);

    while (getIsRunning())
    {
	timeval lastTime;
	timeval currentTime;

	// Get current micorsecond time
	gettimeofday(&lastTime, NULL);

	// Do a msleep()
	QThread::msleep(m_waitInterval);

	// Get the microsecond time after msleep
	gettimeofday(&currentTime, NULL);

	// Calculate the difference
	int difference;
	difference = currentTime.tv_usec - lastTime.tv_usec;
	qDebug() << objectName() << difference;
    }
}
